package com.business.action.basic;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.business.bean.basic.WorkTypeBean;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import net.sf.rose.jdbc.PageBean;
import net.sf.rose.jdbc.dao.BeanDAO;
import net.sf.rose.jdbc.query.BeanSQL;
import net.sf.rose.jdbc.service.Service;
import net.sf.rose.web.util.WebUtils;

/**
 * 工种信息
 * 
 * @author fengjian
 *
 */
@Controller
@RequestMapping("/basic/workType")
public class WorkTypeAction {

	/**
	 * @description 查询工种
	 * @author jiangwenfeng
	 * @date 创建时间：2019/10/17 22:00
	 */
	@ResponseBody
	@RequestMapping("/getWorkTypeListByMap.do")
	public List<WorkTypeBean> getWorkTypeListByMap(HttpServletRequest request, Service service) {
		Map<String, Object> map = WebUtils.getRequestData(request);
		BeanDAO dao = new BeanDAO(service);
		BeanSQL query = dao.getQuerySQL();
		query.setEntityClass(WorkTypeBean.class);
		query.createSql(map);
		return dao.list();
	}

	/**
	 * 
	 */
	@ResponseBody
	@RequestMapping("/save.do")
	public PageBean save(Service service, WorkTypeBean bean) {
		PageBean res = new PageBean();
		BeanDAO dao = new BeanDAO(service);
		BeanSQL query = dao.getQuerySQL();
		query.setEntityClass(WorkTypeBean.class);
		query.createSql("jobID", bean.getJobID());
		WorkTypeBean wt = dao.get();
		if (wt != null) {
			query.createUpdateSql(bean);
		} else {
			query.createInsertSql(bean);
		}
		if (dao.update() > 0) {
			res.setMessage("保存信息成功！");
		} else {
			res.setSuccess(false);
			res.setMessage("保存信息失败！");
		}
		return res;
	}

}
